#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void func(void)
{

	int i = 1;
	// (++i) + (++i);
	// printf("i: %d   %d\n", i, (++i) + (++i));

	int Sensor_Total_Width = 0, Sensor_Shoulder_Width = 0;
	char buf[100] = "090000;001000";

	sscanf(buf, "%04d;%04d", &Sensor_Total_Width, &Sensor_Shoulder_Width);
	printf("Sensor_Total_Width: %4d   Sensor_Shoulder_Width: %4d\n",
		   Sensor_Total_Width,
		   Sensor_Shoulder_Width);

	Sensor_Total_Width = 999999;
	Sensor_Total_Width = Sensor_Total_Width % 10000;
	sprintf(buf, "%04d;%04d;%03d;", Sensor_Total_Width, Sensor_Shoulder_Width, 1233 % 100);
	printf("buf: %s\n", buf);

	// 算术优先级测试
	printf("calc test\n");
	int32_t Step = 0, Number[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};

	Step = Number[0] -
		   (Number[1] / 2) +
		   Number[2] -
		   Number[3] -
		   (Number[4] / 2);

	printf("Step: %d\n", Step);

	uint16_t num[20] = {0};
	num[1] = 0xffff;
	num[2] = 0x66;
	num[3] = num[1] & 0x0000ffff;
	num[4] = num[1] >> 16;
	sprintf(buf, "%#x %#x %#x %#x \n", num[1], num[2], num[3], num[4]);
	printf("buf: %s\n", buf);
}

void func2(void)
{
	// func();

	// uint8_t str[] = {"CM2;a34dd;43dd324;c43243d;QW4324234;TR432443;"},
	// 		buf[10][10] = {0};
	// sscanf(str, "CM%6[^;];%6[^;];%6[^;];%6[^;];%6[^;];%6[^;];", buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);

	// for (uint8_t i = 0; i < sizeof(buf) / sizeof(buf[0]); i++)
	// {
	// 	printf("buf[%d]: %s\n", i, buf[i]);
	// }

	//  0000 0011
	//  0000 0010
	//  0000 0001
	printf("%d %d %d \n",
		   0x3 & 0x30,
		   0x2 & 0x2,
		   0x3 & 0x4);

	uint16_t out_data1 = 0x4; // 大显示绿色灯亮 0000 0100
	out_data1 &= 0xdf;		  // 关闭蜂鸣器	1101 1111

	printf("out_data1: %x\n", out_data1);

	uint8_t buf[5] = {0};
	sscanf("123.157.169.124", "%hhu.%hhu.%hhu.%hhu", &buf[0], &buf[1], &buf[2], &buf[3]);
	printf("buf[0]: %d buf[1]: %d buf[2]: %d buf[3]: %d\n", buf[0], buf[1], buf[2], buf[3]);
}

int main(void)
{

	uint8_t buf[5] = {0};
	int ret[2] = {0};

	ret[0] = sscanf("#123.157.169.125#", "*%hhu.%hhu.%hhu.%hhu#", &buf[0], &buf[1], &buf[2], &buf[3]);
	printf("ret[0]: %d [%d.%d.%d.%d]\n", ret[0], buf[0], buf[1], buf[2], buf[3]);

	ret[1] = sscanf("*123.157.169.126*#", "*%hhu.%hhu.%hhu.%hhu#", &buf[0], &buf[1], &buf[2], &buf[3]);
	printf("ret[1]: %d [%d.%d.%d.%d]\n", ret[1], buf[0], buf[1], buf[2], buf[3]);
	printf("ret[1]: %d [%d.%d.%d.%d]\n", ret[1], buf[0], buf[1], buf[2], buf[3]);

	return 0;
}